package cn.wit.job.controller;

import cn.wit.job.condition.SearchCompanyCondition;
import cn.wit.utils.pojo.Company;
import cn.wit.job.service.CompanyService;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/job/company")
@CrossOrigin
@Api(tags = "公司管理")
public class CompanyController {
    private Logger logger = LoggerFactory.getLogger(CompanyController.class);

    @Autowired
    private CompanyService companyService;

    @PostMapping("/insertCompany")
    @ApiOperation("公司新增")
    public Result insertCompany(@RequestBody Company c) {
        return this.companyService.insert(c);
    }
    @PutMapping("/deleteCompany/{id}")
    @ApiOperation("公司删除")
    public Result deleteCompany(@PathVariable("id") int id) {
        return this.companyService.deleteById(id);
    }

    @PutMapping("/updateCompany")
    @ApiOperation("公司更新")
    public Result updateCompany(@RequestBody Company c) {
        return this.companyService.updateById(c);
    }

    @GetMapping("/selectAllCompany")
    @ApiOperation("全部查询所有公司")
    public Result selectCompanyAll() {
        return this.companyService.selectAllCompany();
    }

    @GetMapping("/searchCompany/{num}/{size}")
    @ApiOperation(value = "条件搜索招聘信息")
    public Result searchRecruitInfo(@PathVariable("num") int num,
                                    @PathVariable("size") int size,SearchCompanyCondition condition) {
        IPage<Company> page = new Page<>(num, size);
        return this.companyService.searchPage(page, condition);
    }

    @GetMapping("/download/company/template")
    @ApiOperation(value = "获取excel文件下载链接")
    public String downloadExcel(){
        return "http://localhost:9000/company.xlsx";//返回前端一个下载链接
    }

    @PostMapping("/importExcel")
    @ApiOperation(value = "Excel导入公司信息")
    public Result excelCompanyInfo(@RequestParam("file") MultipartFile file){
        //将接受到的excel文件传入service业务层
        return this.companyService.excelImport(file);
    }

}
